package com.lzs.chuku.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzs.entity.Outorder;
import com.lzs.chuku.feign.KucunFeign;
import com.lzs.chuku.mapper.OutorderMapper;
import com.lzs.chuku.service.OutorderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lzs.util.R;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 刘中帅
 * @since 2020-11-23
 */
@Service
public class OutorderServiceImpl extends ServiceImpl<OutorderMapper, Outorder> implements OutorderService {

    @Autowired
    private KucunFeign kucunFeign;
    @Autowired
    private OutorderMapper outorderMapper;
    @Override
    public R findOutorderPageBy(Outorder outorder, Integer currentPage, Integer pageSize) {
        Page<Outorder> page=new Page<>(currentPage,pageSize);
        try {
            String outrderno=outorder.getOutorderno();
            String state=outorder.getState();
            String receiver =outorder.getReceiver();
            String begintime=outorder.getBegintime();
            String finishtime=outorder.getFinishtime();
            String province=outorder.getProvince();
            String city=outorder.getCity();
            String county=outorder.getCounty();
            QueryWrapper<Outorder> wrapper=new QueryWrapper<>();
            if (StringUtils.isNotEmpty(outrderno)){
                wrapper.like("outorderno",outrderno);
            }
            if (StringUtils.isNotEmpty(state)){
                wrapper.eq("state",state);
            }
            if (StringUtils.isNotEmpty(receiver)){
                wrapper.like("receiver",receiver);
            }
            if (begintime!=null&&finishtime!=null){
                wrapper.between("depottime",begintime,finishtime);
            }else if (begintime==null&&finishtime!=null){
                wrapper.le("depottime",finishtime);
            }else if (finishtime==null&&begintime!=null){
                wrapper.ge("depottime",begintime);
            }

            if (StringUtils.isNotEmpty(province)){
                wrapper.eq("province",province);
            }
            if (StringUtils.isNotEmpty(city)){
                wrapper.eq("city",city);
            }
            if (StringUtils.isNotEmpty(county)){
                wrapper.eq("county",county);
            }
            outorderMapper.selectPage(page,wrapper);
            return (R.ok().message("查询成功").data("page",page));
        }catch (Exception e){
            return R.error().message("查询失败");
        }
    }

    @Override
    public R changestate(List<Long> outorderids, String state) {
        int b=outorderMapper.changestate(outorderids,state);
        if (b>0){
            return R.ok().message("成功");
        }
        return R.error().message("失败");
    }


}
